
/*
 *
 *  The longest sequence of non-repeating characters.
 *
 * */
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
using namespace std;

int main(int argc, const char *argv[])
{
    vector<char> srcSeq;
    vector<int>  tables;
    vector<char> resSeq;
    vector<char> tmp;
    char zuTable[255] = {0};
    int MaxIdx, MinIdx;
    int MaxVal, MinVal; // The value of tables vector.
    int i, n, j;
    char c;
    cin >> n;
    srand((unsigned)time(NULL));
    for (i = 0; i < n; i++) {
        while (1) {
            c = rand()%255;
            if (((65 <= c) && (c <= 90))) 
                //    || ((97 <= c) && (c <= 122)))
                break;
        }
        srcSeq.push_back(c);
        cout << srcSeq[i] << "\t\t";
    }
    cout << endl;
    tables.resize(srcSeq.size());
    char f;
    for (i = 0; i < srcSeq.size(); i++) {
        f = srcSeq[i];
        for (j = i + 1; j < srcSeq.size(); j++) {
            if (f == srcSeq[j]) {
                tables[i] = tables[j] = 1;
            }
        }
    }
    for (i = 0; i < tables.size(); i++) {
        cout << tables[i] << "\t\t";
    }
    cout << endl;
    
    // Second processing.
    for (i = 0; i < tables.size(); i++) {
        if (!tables[i]) {
            //MinIdx = i;
        } else {
            continue;
        }
        for (j = i + 1; j < tables.size(); j++) {
            if (tables[j]) {
                //MaxIdx = j - 1;
                break;
            }
        }
        if (MaxVal < (j - 1 - i)) {
           MaxIdx = j - 1;
           MinIdx = i;
            MaxVal = (j - 1 - i) + 1;
        }
    }

    cout << "get the min index and max index:" << MinIdx << MaxIdx << endl;
    cout << "get the max size:" << MaxVal << endl;
    if (MinIdx && ((MaxIdx - 1) < srcSeq.size())) {
        if (srcSeq[MinIdx - 1] == srcSeq[MaxIdx + 1]) {
            cout << "there are two seq:" << endl;
            for (int i = MinIdx - 1; i < MaxIdx + 1; i++)
                cout << srcSeq[i] << "\t\t";
            cout << endl;
            for (int i = MinIdx; i < MaxIdx + 2; i++)
                cout << srcSeq[i] << "\t\t";
            cout << endl;
        } else {
            cout << "there is one seq:";
            for (int i = MinIdx - 1; i < MaxIdx + 2; i++)
                cout << srcSeq[i] << "\t\t";
            cout << endl;
        }
    } else {
        if (!MinIdx) {
            cout << "there is one seq:";
            for (int i = MinIdx; i < MaxIdx + 2; i++)
                cout << srcSeq[i] << "\t\t";
            cout << endl;
        } else if ((MaxIdx+1) == srcSeq.size()) {
            
            cout << "there is one seq:";
            for (int i = MinIdx -1 ; i < MaxIdx + 2; i++)
                cout << srcSeq[i] << "\t\t";
            cout << endl;
        }
    }

#if 0
    //  The first processing.
    tables.resize(srcSeq.size());
    for (i = 0; i < srcSeq.size(); i++) {
        zmTable[srcSeq[i]-'0'] ++;
        if (!i) {
            tables[i] = 1;
        } else {
            if (zmTable[srcSeq[i]-'0']) {
            }
            tables[i] = (srcSeq[i]==srcSeq[i-1]) ? 0 : 1; 
        }
        cout << tables[i] << "\t\t";
    }
    cout << endl;
#endif
    return 0;
}
